@extends('admin.main')
@section('body')
    <div class="main-title">
        <h2>老客户导入</h2>
    </div>
    <div class="tab-wrap">
        <ul class="tab-nav nav">
                <li class="current" id="stl"><a href="javascript:;" id="st">初始水桶</a></li>
                <li id="spl"><a href="javascript:;" id="sp">初始水票</a></li>
        </ul>
        <div class="tab-content">
            <form action="" method="post" class="form-horizontal">
                <div class="form-item">
                    <label class="item-label">
                        客户名称：<span class="check-tips">{{$member['name']}}</span>
                    </label>
                </div>
                <div class="form-item">
                    <label class="item-label">
                        客户电话：<span class="check-tips">{{$member['mobile']}}</span>
                    </label>
                </div>
                <div class="form-item">
                    <label class="item-label">
                        客户地址：<span class="check-tips">{{$member['address']}}</span>
                    </label>
                </div>
                <input type="hidden" name="type" value="0" id="type">
                <div class="form-item">
                    <label class="item-label">
                        选择店铺：
                            <span class="check-tips">
                                <select name="shop_id" id="shop_id">
                                    @if(count($shopList))
                                        @foreach($shopList as $v)
                                            <option value="{{$v['id']}}">{{$v['shop_name']}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </span>
                    </label>
                </div>
                <div id="bucket">
                    <div class="form-item">
                        <label class="item-label">
                            水桶品牌：
                            <span class="check-tips">
                                <select name="bucket_category" id="bucket_category"></select>
                            </span>
                        </label>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            水桶数量：
                            <span class="check-tips">
                                <input type="text" name="bucket_num" class="text input-small" value="{{$member['initial_bucket_num']}}">
                            </span>
                        </label>
                    </div>
                    @if(!$member['import_bucket'])
                    <div class="form-item">
                        <label class="item-label"></label>
                        <div class="controls">
                            <input type="hidden" name="mid" value="{{request('id')}}">
                            <button type="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确 定 </button>
                            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
                        </div>
                    </div>
                        @else
                        <div class="form-item">
                            <span class="check-tips">该客户已导入初期水桶数据</span>
                        </div>
                    @endif
                </div>
                <div id="waterbill" style="display: none">
                    <div class="form-item">
                        <label class="item-label">
                            水票名称：
                            <span class="check-tips">
                                <select name="waterbill_id" id="waterbill_id"></select>
                            </span>
                        </label>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            水票数量：
                            <span class="check-tips">
                                <input type="text" name="waterbill_num" class="text input-small" value="0">
                            </span>
                        </label>
                    </div>
                    @if(!$member['import_waterbill'])
                        <div class="form-item">
                            <label class="item-label"></label>
                            <div class="controls">
                                <input type="hidden" name="mid" value="{{$member['id']}}">
                                <input type="hidden" name="shop_id" value="{{$member('shop_id')}}">
                                <input type="hidden" name="admin_id" value="{{$member('admin_id')}}">
                                <button type="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确 定 </button>
                                <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
                            </div>
                        </div>
                    @else
                        <div class="form-item">
                            <span class="check-tips">该客户已导入初期水票数据</span>
                        </div>
                    @endif
                </div>
            </form>
        </div>
    </div>
@endsection

@section('script')
    <script>
        var categoryData = JSON.parse('{!! json_encode($bucketData) !!}');
        var waterBillData = JSON.parse('{!! json_encode($waterBill) !!}');
        $(window).ready(function () {
            var shop_id = $('#shop_id').val();
            changeOptions(categoryData, shop_id, 'bucket_category')
            changeBillOptions(waterBillData, shop_id, 'waterbill_id')
        });
        function changeOptions(categoryData, shop_id, target) {
            var options = '';
            for (var i in categoryData) {
                if (categoryData[i].shop_id == shop_id) {
                    options += "<option value='" + categoryData[i].bucket_category_id + "'>" + categoryData[i].category.title + "</option>";
                }
            }
            $("#" + target).append(options);
        }
        function changeBillOptions(waterBillData, shop_id, target) {
            var options = '';
            for (var i in waterBillData) {
                if (waterBillData[i].shop_id == shop_id) {
                    options += "<option value='" + waterBillData[i].id + "'>" + waterBillData[i].goods_name + "</option>";
                }
            }
            $("#" + target).append(options);
        }
        $('#shop_id').change(function () {
            var shop_id = $(this).val();
            $("#bucket_category").empty();
            $("#waterbill_category").empty();
            changeOptions(categoryData, shop_id, 'bucket_category')
            changeBillOptions(waterBillData, shop_id, 'waterbill_category')
        });
        $("#st").click(function(){
            $("#spl").removeClass('current');
            $("#stl").addClass('current');
            $("#waterbill").hide();
            $("#bucket").show();
            $("#type").val(0);
        });
        $("#sp").click(function(){
            $("#stl").removeClass('current');
            $("#spl").addClass('current');
            $("#bucket").hide();
            $("#waterbill").show();
            $("#type").val(1);
        });
    </script>
@endsection